<?php


namespace Home\Controller;

use Home\Model\UserModel;
use Think\Controller;

class UserController extends Controller
{
    public function register()
    {
        $userModel = D('User');
//        $userModel=new UserModel();
        if (empty($_POST)) {
            $this->display();
        } else {
            $info = $userModel->create();
            dump($info);
            dump($userModel->getError());
            if ($info) {
                $info['user_hobby'] = implode(',', $info['user_hobby']);
                $info['user_time'] = time();
                $res = $userModel->add($info);
                if ($res !== false) {
                    $this->redirect('index/index', [], 2, '注册成功');
                }
            } else {
                $this->display();
            }
        }
    }
    public function checkName($name){
            $info=D('user')->where("username='$name'")->find();
            echo $info?true:false;
    }
}